package com.yljk.homedoctor.adapter;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yilijk.base.utils.ALog;
import com.yilijk.base.utils.UIUtils;
import com.yljk.homedoctor.R;
import com.yljk.homedoctor.model.entity.LiveListEntity;

import java.util.List;

public class LiveAdapter extends BaseQuickAdapter<LiveListEntity.DataBean.ListBean, BaseViewHolder> {

    private final int LIVE_NOW = 0;
    private final int LIVE_STAY = 1;
    private final int LIVE_BACK = 2;
    private final int LIVE_AGAIN = 3;


    private String[] statuses = new String[]{
        "直播中",
        "待开始",
        "已结束",
        "回放",
    };

    private int[] icons = new int[]{
            R.mipmap.ic_live_git,
            R.mipmap.icon_stay,
            R.mipmap.icon_back,
            R.mipmap.icon_back,
    };


    public LiveAdapter(@Nullable @org.jetbrains.annotations.Nullable List<LiveListEntity.DataBean.ListBean> data) {
        super(R.layout.homefragment_live_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, LiveListEntity.DataBean.ListBean item) {
        if (helper.getPosition() == 0) {
            LinearLayout ll = helper.getView(R.id.live_item);
            LinearLayout.LayoutParams rowparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            rowparams.setMargins(0,0, UIUtils.dp2px(mContext,5),0);
            ll.setLayoutParams(rowparams);
        }
        int status = 0;

        if (item.getLive_status() == 51){

            status = LIVE_NOW;

        }else if (item.getLive_status() == 50){

            status = LIVE_STAY;

        }else if (item.getLive_status() == 60){

            status = LIVE_BACK;

        }else if (item.getLive_status() == 61){

            status = LIVE_AGAIN;

        }

        if (status == LIVE_NOW){
            helper.setBackgroundRes(R.id.live_status_bg,R.drawable.live_status_bg);
        }else if (status == LIVE_STAY){
            helper.setBackgroundRes(R.id.live_status_bg,R.drawable.live_stay_bg1);
        }else{
            helper.setBackgroundRes(R.id.live_status_bg,R.drawable.live_stay_bg);
        }

        if (item.getViewer_count() == null || TextUtils.isEmpty(item.getViewer_count())){
            helper.setVisible(R.id.live_status_clicks,false);
        }else{
            helper.setVisible(R.id.live_status_clicks,false);
            ALog.i(TAG, "convert: "+item.getViewer_count());
            helper.setText(R.id.live_status_clicks," "+item.getViewer_count()+" ");
        }
        Glide.with(mContext).load(item.getCover_image()).into((ImageView) helper.getView(R.id.live_background));
        Glide.with(mContext).load(icons[status]).transform(new CenterCrop()).into((ImageView) helper.getView(R.id.live_status_img));
        helper.setText(R.id.live_status_title,statuses[status]);
        helper.setText(R.id.live_title,item.getTitle());
        helper.setText(R.id.live_data,item.getStarted_at());


    }
}
